import router from "@/router";
import Vue from 'vue';
import { Toast } from 'vant';
import request from "@/utils/request";
Vue.use(Toast);
export default {
  namespaced: true,
  state() {
    return {
      currentCity: "上海",
      mapValue:"",
      maplist:[]
    };
  },
  mutations: {
    updateCity(state, val) {
      state.currentCity = val.label;
      state.mapValue=val.value
      router.push("/layout/home");
    },
    allCity(state, val) {
      const arr = ["北京", "上海", "广州", "深圳"];
      if (arr.includes(val.label)) {
        state.currentCity = val.label;
         state.mapValue=val.value
        router.push("/layout/home");
      }else{
        Toast('该城市暂无房源');
      }
    },
    unMapList(state,newMaplist){
         state.maplist=newMaplist
    }
  },
  actions: {
    async getMapList(state,value){
     const res= await  request({
        url:'/area/map',
        params:{
          id:value
        },
        method: 'get'
      })
      state.commit('unMapList',res.body)
    }
    
     
   
  }
};
